package com.zhaoc.web.action;

import com.opensymphony.xwork2.ActionContext;
import com.zhaoc.domain.take_delivery.Order;
import com.zhaoc.service.IOrderService;
import com.zhaoc.web.base.BaseAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>title:com.zhaoc.web.action</p>
 * date:2018/8/16 0016
 * time:21:14
 * author:赵成
 * user:13566
 */
@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class OrderAction extends BaseAction<Order> {

    @Autowired
    private IOrderService orderService;

    @Action(value = "order_findByOrderNum",results = {@Result(name = SUCCESS,type = "json")})
    public String findByOrderNum(){
        Order order = orderService.findByOrderNum(model.getOrderNum());
        Map<String,Object> result = new HashMap<String, Object>();
        if (order == null){
            //订单号不存在
            result.put("success",false);
        }else {
            //查询到对应的订单
            result.put("success",true);
            result.put("orderData",order);
        }
        ActionContext.getContext().getValueStack().push(result);
        return SUCCESS;
    }

}
